package ch.simas.javaee6examples.web;

import ch.simas.javaee6examples.model.Employee;
import ch.simas.javaee6examples.service.EmployeeService;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Simon
 */
@ManagedBean
@SessionScoped
public class EditBean implements Serializable {

    @EJB
    private EmployeeService employeeService;
    private Employee employee;

    public void save() {
        employee = employeeService.save(employee);
    }

    public String saveAndClose() {
        employeeService.save(employee);
        employee = null;

        return "/index.xhtml";
    }

    public String edit(Employee employee) {
        this.employee = employee;

        return "/edit.xhtml";
    }

    public String create() {
        this.employee = new Employee();

        return "/edit.xhtml";
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }
}
